package com.qian.fmall.order.controller;

import com.qian.fmall.commons.ResultSet;
import com.qian.fmall.order.orderInterface.OrderService;
import com.qian.fmall.pojo.Orders;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@RestController
@RequestMapping("order")
@CrossOrigin
public class OrderController {
    @DubboReference
    private OrderService orderService;
    @RequestMapping("add")
    public ResultSet addOrder(String cids,@RequestBody Orders order)
    {
        System.out.println("---------orderController");
        String[] split = cids.split(",");
        int[] arr=new int[split.length];
        for (int i=0;i<split.length;i++) {
            arr[i] = Integer.parseInt(split[i]);
        }
        order.setCreateTime(new Date());
        order.setOrderId(UUID.randomUUID().toString().replace("-",""));
        order.setStatus("1");
        order.setDeleteStatus(0);
        order.setCreateTime(new Date());
        return orderService.addOrder(arr,order);
    }
}
